﻿using UnityEngine;
using System.Collections;

public class NPCScript : MonoBehaviour
{
	public static readonly int FORMULIR_STATE = 0;
	public static readonly int BAYAR_STATE = 1;
	public static readonly int FOTO_STATE = 2;
	public static readonly int PENGAMBILAN_STATE = 3;
	public static readonly int FIN_STATE = 4;

	public static readonly int NPC_WAIT_STATE = 5;
	public static readonly int NPC_ACTION_STATE = 6;

	public Sprite happy;
	public Sprite normal;
	public Sprite megusta;

	int procedurState;
	int npcState;
	int score;
	float timeElapsed;
	public GameObject objPosition;

	void Awake()
	{
		this.score = 1000;
		this.timeElapsed = 0;
		this.procedurState = FORMULIR_STATE;
		this.npcState = NPC_WAIT_STATE;
	}

	void Start()
	{
		this.GetComponent<SpriteRenderer>().sprite = happy;
	}

	public int ProcedureState
	{
		get{return this.procedurState;}
		set{this.procedurState = value;}
	}

	public int NPCState
	{
		get{return this.npcState;}
		set{this.npcState = value;}
	}

	void Update()
	{
		if(this.npcState == NPC_WAIT_STATE)
		{
			if(this.timeElapsed < 60f)
			{
				this.timeElapsed += Time.deltaTime;
				if(this.timeElapsed > 60f)
					this.timeElapsed = 60f;
			}
			if(this.timeElapsed > 30 && this.timeElapsed < 60)
				this.GetComponent<SpriteRenderer>().sprite = normal;
			else if(this.timeElapsed == 60)
				this.GetComponent<SpriteRenderer>().sprite = megusta;
		}
	}

	void OnTriggerEnter(Collider other)
	{
		this.objPosition = other.gameObject;
	}

	void OnTriggerExit(Collider other)
	{
		this.objPosition = null;
	}

	public int Score
	{
		get{return this.score - ((int)timeElapsed*10);}
	}
}
